package edu.tongji.libraryapp;

import java.util.ArrayList;

import edu.tongji.libraryapp.adapter.MyCollectListAdapter;
import edu.tongji.libraryapp.model.CollectItem;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ListView;
import android.widget.TextView;

public class MyCollectActivity extends Activity {

	@Override
	protected void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_my_collect);

		bindUserInteraction();
		initMyCollectListView();
	}

	private void bindUserInteraction() {
		TextView myCollectTitleText = (TextView) findViewById(R.id.myCollectTitleText);
		myCollectTitleText.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				Intent mainIntent = new Intent();
				mainIntent.setClass(MyCollectActivity.this, MainActivity.class);
				startActivity(mainIntent);
				overridePendingTransition(R.anim.slide_in_right,
						R.anim.slide_out_right);
			}
		});
	}

	private void initMyCollectListView() {
		ListView myCollectListView = (ListView) findViewById(R.id.myCollectListView);
		ArrayList<CollectItem> myCollectList = new ArrayList<CollectItem>();
		for (int i = 0; i < 5; i++) {
			myCollectList.add(new CollectItem());
		}
		MyCollectListAdapter myCollectListAdapter = new MyCollectListAdapter(
				getApplicationContext(), this, myCollectList);
		myCollectListView.setAdapter(myCollectListAdapter);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			Intent mainIntent = new Intent();
			mainIntent.setClass(MyCollectActivity.this, MainActivity.class);
			startActivity(mainIntent);
			overridePendingTransition(R.anim.slide_in_right,
					R.anim.slide_out_right);
		}
		return true;
	}
}
